<template>
  <div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>原密码</label>
					<input id='old_password' type="password" class="mui-input-clear mui-input" v-model="old_password" placeholder="请输入密码">
					
				</div>
                <div class="mui-input-row">
					<label>新密码</label>
					<input id='u_password' type="password" class="mui-input-clear mui-input" v-model="u_password" placeholder="请输入密码">
				</div>
			</form>
			<div class="mui-content-padded">
				<button  class="mui-btn mui-btn-block mui-btn-primary" @click='putpassword'>提交</button>
			</div>
			
		</div>
</template>

<script>
import {Toast} from 'mint-ui'
export default {
   data(){
       return{
		   pid:'',
		   pwd:'',
		   old_password:'',
		   u_password:'',
		   
       }
   },
   methods:{
	   putpassword(){
		if(this.pwd==this.old_password){
			let person={
				"u_password":this.u_password,
				"u_id":this.pid
			}
		     this.$ajax({
			   url:'users/user',
			   method:'put',
			   data:person
		   }).then(resp=>{
			   Toast("密码修改成功")
			 this.$router.push("/user/login")
		   })
	   }else{
		    Toast("原密码不正确");
             return;
	   }
	}
		    
   },
   created(){
	 let userInfo= JSON.parse(localStorage.getItem("userInfo"))[0]
	 this.pid=userInfo.u_id
	 this.pwd=userInfo.u_password
   }
}
</script>

<style scoped>

</style>